package com.tanjie.blackbean.system.admin.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.tanjie.blackbean.mybatis.query.PageParam;
import com.tanjie.blackbean.system.admin.model.permission.PermissionDTO;
import com.tanjie.blackbean.system.admin.model.permission.PermissionPO;
import com.tanjie.blackbean.system.admin.model.permission.PermissionQuery;
import com.tanjie.blackbean.system.admin.model.permission.PermissionVO;
import com.tanjie.blackbean.system.admin.service.IPermissionService;
import com.tanjie.blackbean.web.annotation.BlackBeanController;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 权限表
 *
 * @author tanjie
 * @since 2022-04-21
 */
@Tag(name = "权限表")
@BlackBeanController
@RequestMapping("permission")
public class PermissionController {

    @Resource
    IPermissionService permissionService;

    @Operation(summary = "新增")
    @PostMapping("create")
    public void createPermissionHandler(@RequestBody @Validated PermissionDTO dto) {
        permissionService.create(dto);
    }

    @Operation(summary = "更新")
    @PostMapping("update")
    public void updatePermissionHandler(@RequestBody @Validated PermissionDTO dto) {
        permissionService.update(dto);
    }

    @Operation(summary = "删除")
    @GetMapping("delete")
    public void deletePermissionHandler(String id) {
        permissionService.delete(id);
    }

    @Operation(summary = "获取详情")
    @GetMapping("detail")
    public PermissionVO getPermissionDetailHandler(String id) {
        return permissionService.detail(id);
    }

    @Operation(summary = "列表查询")
    @PostMapping("list")
    public List<PermissionVO> queryPermissionListHandler(@RequestBody(required = false) PermissionQuery dto) {
        return permissionService.queryList(dto);
    }

    @Operation(summary = "分页查询")
    @PostMapping("page")
    public IPage<PermissionVO> queryPageListHandler(@RequestBody(required = false) PermissionQuery dto, PageParam pageParam) {
        return permissionService.queryPage(dto, pageParam);
    }

    @Operation(summary = "获取角色已绑定权限")
    @GetMapping("listByRoleId")
    public List<String> listByRoleIdHandler(@RequestParam("roleId") String roleId) {
        return permissionService.listByRoleId(roleId);
    }

    @Operation(summary = "菜单id查询权限")
    @GetMapping("listByMenuId")
    public List<PermissionPO> permissionListByMenuIdHandler(@RequestParam("menuId") String menuId) {
        return permissionService.listByMenuId(menuId);
    }

}
